package com.qf.util;

import io.netty.channel.Channel;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class ChannelUtil {

    private static Map<String, Channel> channelMap = new ConcurrentHashMap<>();

    public static void putChannel(String devid, Channel channel){
        channelMap.put(devid, channel);
    }

    public static void delChannel(String devid){
        channelMap.remove(devid);
    }

    public static void delChannel(Channel channel){
        for (Map.Entry<String, Channel> entry : channelMap.entrySet()) {
            if (entry.getValue() == channel) {
                delChannel(entry.getKey());
            }
        }
    }

    public static Channel getChannel(String devid){
        return channelMap.get(devid);
    }
}
